<template>
	 <mdp-table v-if="columnCfgs && columnCfgs.length>0" currOpType="mng" operWidth="200" :params="{tableName:modelValue,dataSource:dataSource}"  ref="tableFieldListRef" :columnCfgs="columnCfgs" :crudApis="crudApis"/>
</template> 
<script> 
import {listTableData,addTableData,delTableData,batchDelTableData,editSomeFieldsTableData} from '@/api/mdp/dm/data'
import {getTableColumnList} from '@/api/mdp/dm/meta'
export default {
	name: 'MdpInputTableName', 
	props: {
		modelValue: {
			type:[String,Array,Object],
			default:function(){
				return null
			}
		},
		dataSource:{
			type:String,
			default:'master'
		}
	},
	data(){
		return {  
			columnCfgs:[
				
			],
			crudApis:{
				list:listTableData,
				add: addTableData,
				del: delTableData,
				batchDel: batchDelTableData,
				editSomeFields: editSomeFieldsTableData
			}
		}
	},
	computed: {
		value:{
			set(val){
				this.$emit('update:modelValue',val)
			},
			get(){
				return this.modelValue
			}
		}
	}, 
	methods:{ 
		doSearch(){  
			if(!this.value){
				return;
			}
			this.$refs['tableFieldListRef']?.searchTableDatas();
		}
	},
	async created(){
		let {data,tips}=await getTableColumnList({dataSource:this.dataSource,tableName:this.value}) 
			if(tips.isOk){
				this.columnCfgs=data.map(f=>{
					var col={label:f.remarks,property:f.camelsColumnName,colType:f.dataType}
					return col;
				})
			} 
	},
	mounted() { 
	}
}
</script>
